package remote_work.core.service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import remote_work.dto.InputObject;
import remote_work.dto.OutputObject;
import remote_work.util.DBHelper;
import remote_work.util.MyService;

/**
 * @author LiuPing
 *
 * 2018年3月21日
 */
@MyService
public class LoginService {

	/**
	 * 登录
	 * 
	 * @param inputObject
	 * @return
	 * @throws SQLException 
	 */
	public OutputObject login(InputObject inputObject) throws SQLException {
		OutputObject outputObject = new OutputObject();
		//TODO:保存当前登录学生的信息，应该也不用保存，登录之后暂时就没用了 
		DBHelper db = new DBHelper();
		String sql = "select * from USERINFO where userid=? and userpwd=?";
		List<Object> params = new ArrayList<>();
		params.add(inputObject.getValue("user"));
		params.add(inputObject.getValue("pwd"));
		List<Map<String, Object>> result = db.find(sql, params);
		if (result.size() > 0) {
			outputObject.setReturnCode("0");
			outputObject.setBean(result.get(0));
		} else {
			outputObject.setReturnCode("-1");
		}
		return outputObject;
	}
}
